//
//  StrategyStringParameter.m
//  StrategyInspector
//
//  Created by jiro on 12/07/29.
//  Copyright 2012 jiro music. All rights reserved.
//

#import "StrategyStringParameter.h"

StrategyStringParameter::StrategyStringParameter()
{
	type = StrategyParameter::Type_String;
}

StrategyStringParameter::StrategyStringParameter( NSString* s )
{
	type = StrategyParameter::Type_String;
	strings.push_back( s );
	currentIndex = 0;
}

StrategyStringParameter::StrategyStringParameter( const std::vector< NSString* >& stringsArg )
{
	type = StrategyParameter::Type_String;
	strings = stringsArg;
	currentIndex = 0;
}

bool StrategyStringParameter::isMutable() const
{
	if ( strings.size() == 1 )
	{
		return true;
	}
	return false;
}

void StrategyStringParameter::nextValue( bool& isLast )
{
	currentIndex++;
	if ( currentIndex >= strings.size() )
	{
		isLast = true;
	}
	else
	{
		isLast = false;
	}
}

void StrategyStringParameter::initialize()
{
	currentIndex = 0;
}

NSString* StrategyStringParameter::getStringValue() const
{
	return strings[ currentIndex ];
}


void StrategyStringParameter::setStringValue( NSString* s )
{
	if ( isMutable() )
	{
		strings[ 0 ] = s;
		return;
	}
	
	for ( int i = 0, count = strings.size(); i < count; i++ )
	{
		NSString* s2 = strings[ i ];
		if ( [ s2 isEqualToString: s ] )
		{
			currentIndex = i;
			return;
		}
	}

	strings.push_back( s );
	currentIndex = strings.size() - 1;
}

StrategyParameter* StrategyStringParameter::copy() const
{
	StrategyStringParameter* p = new StrategyStringParameter( strings );
	return p;
}

void StrategyStringParameter::setValueMiddle()
{
	currentIndex = strings.size() / 2.0;
}
